package com.lin.csdn.dao.impl;

import com.lin.csdn.dao.BaseDao;
import com.lin.csdn.model.po.Report;
import com.lin.csdn.utils.DateView;

import java.util.ArrayList;
import java.util.List;

public class ReportDao extends BaseDao {

    DateView dateView=new DateView();

    public Object search() {
        List<Object> list = new ArrayList<>();
        list.add("否");
        Object data;
        Class<Report> cls= Report.class;
        data=find("SELECT * FROM report where status=?",list,cls);
        return data;
    }

    public int addReport(String context,int blogid){
        List<Object> list=new ArrayList<>();
        String date=dateView.getDate();
        list.add(context);
        list.add(blogid);
        list.add(date);
        list.add("否");
        return update("INSERT INTO report (context,blogid,date,status) VALUES (?,?,?,?)",list);
    }

    public String ban(int reportId){
        List<Object> SList=new ArrayList<>();
        SList.add(reportId);
        Object result;
        //查找对应博客的id
        result=findSingle("SELECT blogid FROM report where id=?",SList);
        String blogId=String.valueOf(result);
        List<Object> BList=new ArrayList<>();
        BList.add(Integer.parseInt(blogId));
        //查找用户id
        result=findSingle("SELECT userid FROM blog where id=?",BList);
        //将举报信息记录为已经处理
        List<Object> RList=new ArrayList<>();
        RList.add("是");
        RList.add(reportId);
        update("UPDATE report SET status=? WHERE id=?",RList);
        //获取用户的id
        String userid=String.valueOf(result);
        List<Object> UList=new ArrayList<>();
        UList.add("是");
        UList.add(Integer.parseInt(userid));
        //封禁账号以及博客
        update("UPDATE user SET status=? WHERE id=?",UList);
        update("UPDATE blog SET status=? WHERE userid=?",UList);

        return "成功封禁"+userid+"的账号和博客";
    }
}
